<template>
	<view class="zai-box">
		<image src="/static/login.png" mode='aspectFit' class="zai-logo"></image>
		<view class="zai-title">宠物领养</view>
		<view class="zai-form">
			<input class="zai-input"  v-model="number" placeholder="请输入用户名" />
			<input class="zai-input"  v-model="password" password placeholder="请输入密码"/>
			<!-- <view class="zai-label">忘记密码？</view> -->
			<button class="zai-btn" @click="to()">立即登录</button>
			<navigator url="/pages/login/register" hover-class="none" class="zai-label">还没有账号？点此注册.</navigator>
		</view>
	</view>
</template>

<script>
	import {
		getToken,
		setToken,
		setExpiresIn,
		setData,
		getData,
		removeToken,
		removeExpiresIn,
		removeData,
		setInvitationId,
		getShareUrl,
		removeShareUrl
	} from '@/utils/auth'
	import { login } from "@/api/login.js"
	export default {
		data() {
			return {
				number:'',
				password:''
			}
		},
		onLoad() {
	// this.judgePlatForm(); //版本升级
		},
		
		mounted() {//记住密码
			
		},
		
		methods: {
			to(){
				login(this.number, this.password,null, null).then((res) => {
					
					let data = res.data
					if (data.code == 200) {
						setToken(data.token);
						// setExpiresIn(data.data.expires_in);
						
						
						if (this.rememberPsw) {
							uni.setStorageSync('HBusername', this.number);
							uni.setStorageSync('HBpassword', this.password);
						} else {//销毁缓存
							uni.removeStorageSync('HBusername');
							uni.removeStorageSync('HBpassword');
						}
						
						//存储用户信息
						setData(data.userId);
						//登录成功 -- 进入首页
						uni.switchTab({
							url: '/pages/index/index'
						})
					} else {
						
						uni.showToast({
							title: data.msg,
							icon: 'none',
							duration: 2000
						});
						
						if(data.msg.indexOf("驳回")>0){
							
							let number = this.number;
							
							setTimeout(function() {
								uni.navigateTo({
									url: '/pages/login/register?phone=' + number
								});
							// window.eventHub.$emit('refreshList', '')// 更新右侧列表状态
							}, 3000)
						}
					}
				})
			},
			
		}
	}
</script>

<style>
	.zai-box{
		padding: 0 100upx;
		position: relative;
	}
	.zai-logo{
		width: 100%;
		width: 100%;
		height: 310upx;
	}
	.zai-title{
		position: absolute;
		top: 0;
		line-height: 360upx;
		font-size: 68upx;
		color: #fff;
		text-align: center;
		width: 100%;
		margin-left: -100upx;
	}
	.zai-form{
		margin-top: 300upx;
	}
	.zai-input{
		background: #e2f5fc;
		margin-top: 30upx;
		border-radius: 100upx;
		padding: 20upx 40upx;
		font-size: 36upx;
	}
	.input-placeholder, .zai-input{
		color: #94afce;
	}
	.zai-label{
		padding: 60upx 0;
		text-align: center;
		font-size: 30upx;
		color: #a7b6d0;
	}
	.zai-btn{
		margin-top: 20px;
		background: #ff65a3;
		color: #fff;
		border: 0;
		border-radius: 100upx;
		font-size: 36upx;
	}
	.zai-btn:after{
		border: 0;
	}
	/*按钮点击效果*/
	.zai-btn.button-hover{
		transform: translate(1upx, 1upx);
	}
</style>
